import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getx_learn/app/common/widgets/widgets.dart';
import 'package:getx_learn/app/modules/navigation_demo/controllers/navigation_demo_controller.dart';
import 'package:getx_learn/app/modules/navigation_demo/modules/navigation1/views/navigation1_view.dart';
import 'package:getx_learn/app/routes/app_pages.dart';

class NavigationDemoView extends GetView<NavigationDemoController> {
  const NavigationDemoView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(context: context, title: Get.arguments),
      body: ListView(
        children: [
          ListTile(
            title: const Text("说明"),
            subtitle: Text('所有的路由，有命名路由，就有类名路由'),
            selected: true,
            selectedColor: Colors.red,
          ),
          Divider(),
          ListTile(
            title: const Text("导航-命名路由"),
            subtitle: Text('Get.toNamed("${Routes.NAVIGATION1}")'),
            onTap: () {
              Get.toNamed(Routes.NAVIGATION1);
            },
          ),
          Divider(),
          ListTile(
            title: const Text("导航-类对象"),
            subtitle: Text('Get.toNamed(${Navigation1View().runtimeType}())'),
            onTap: () {
              Get.to(Navigation1View());
            },
          ),
          Divider(),
          ListTile(
            title: const Text("导航（命名路由）-清除上一个"),
            subtitle: Text('Get.offNamed("${Routes.NAVIGATION1}")'),
            onTap: () {
              Get.offNamed(Routes.NAVIGATION1);
            },
          ),
          Divider(),
          ListTile(
            title: const Text("导航（命名路由）-清除上一个"),
            subtitle: Text('Get.off(${Navigation1View().runtimeType}())，清除上一个页面，再打开新页面)'),
            onTap: () {
              Get.off(Navigation1View());
            },
          ),
          Divider(),
          ListTile(
            title: Text("导航-清除所有"),
            subtitle: Text("Get.offAllNamed('${Routes.NAVIGATION1}')，清除所有页面，再打开新页面"),
            onTap: () => Get.offAllNamed(Routes.NAVIGATION1),
          ),
          Divider(),
          ListTile(
            title: Text("导航(命名导航)-arguments传值+返回值"),
            subtitle: Text(
                'Get.toNamed("${Routes.NAVIGATION2}", arguments: {"id": 888})'),
            onTap: () async {
              var result = await Get.toNamed(Routes.NAVIGATION2,
                  arguments: {"id": 888});
              print("result = ${result}");
            },
          ),

          Divider(),
          ListTile(
            title: Text("导航(命名导航)-parameters传值+返回值"),
            subtitle: Text(
                'Get.toNamed("${Routes.NAVIGATION2}?id=11")'),
            onTap: () async {
              var result = await Get.toNamed("${Routes.NAVIGATION2}?id=11");
              print("result = ${result}");
            },
          ),

          Divider(),
          ListTile(
            title: Text("导航-参数传值+返回值"),
            subtitle: Text('Get.toNamed("${Routes.NAVIGATION2_1.split(":")[0]}7777")'),
            onTap: () async {
              var result = await Get.toNamed("${Routes.NAVIGATION2_1.split(":")[0]}7777");
            },
          ),

          Divider(),
          ListTile(
            title: Text("导航-not found"),
            subtitle: Text('Get.toNamed("/aaa/bbb/ccc")'),
            onTap: ()  {
               Get.toNamed("/aaa/bbb/ccc");
            },
          ),
          Divider(),


          ListTile(
            title: Text("导航-中间件-认证Auth"),
            subtitle: Text('Get.toNamed("${Routes.TEST_MIDDLE_WARE}")'),
            onTap: () => Get.toNamed(Routes.TEST_MIDDLE_WARE),
          ),
          Divider(),



          ListTile(
            title: Text("嵌套导航"),
            subtitle: Text('Get.toNamed("${Routes.NESTED_NAVIGATION}")'),
            onTap: () => Get.toNamed(Routes.NESTED_NAVIGATION),
          ),
          Divider(),

        ],
      ),
    );
  }
}
